import { LessonService } from "@/shared/api/api.lesson";
import { ILesson } from "@/shared/interfaces";
import { QueryClient, useMutation, useQueries, useQuery } from "@tanstack/react-query";
import { AxiosError } from "axios";
import { useEffect, useRef, useState } from "react";



export function useGetLessonById(lessonId: number) {
    const queryClient = new QueryClient


    const getLessonById = useQuery<ILesson, AxiosError<{ message: string }>>(
        {
            queryKey: ['lessons', lessonId],
            queryFn: () => LessonService.getOne(lessonId),
            retry: 3,
            placeholderData: (previousData, previousQuery) => previousData,
        }, queryClient
    );

    const errorMessage = getLessonById.error ? getLessonById.error.response?.data.message : undefined;

    return {
        isSuccess: getLessonById.isSuccess,
        isPending: getLessonById.isPending,
        refetch: getLessonById.refetch,
        errorMessage,
        lesson: getLessonById.data
    };
}